package se.webbzon.boltzmann.hud;

import java.awt.Color;
import java.awt.Dimension;

import se.webbzon.boltzmann.timer.Timer;
import se.webbzon.boltzmann.timer.TimerListener;
import se.webbzon.oschi01.worldarea.WorldArea;
import se.webbzon.oschi01.worldcamera.WorldCameraPane;
import se.webbzon.oschi01.worldobject.WorldObject;

public class BlackOverlay extends WorldObject {
	
	// The timer listener associated with this black overlay
	TimerListener listener;
	
	// The timer associated with this black overlay
	Timer timer;
	
	/*============================================================
	Constructors
	============================================================*/
	
	public BlackOverlay() {
		this(1);
	}

	public BlackOverlay(int steps) {
		super(WorldObject.onCreate + WorldObject.onPostDraw, -100);
		listener = new TimerListenerImpl();
		timer = new Timer(steps);
		timer.addListener(listener);
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	@Override public void onCreate(WorldArea world) {
		timer.start(world);
	}

	@Override public void onPostDraw(WorldArea world, WorldCameraPane hud) {
		Dimension d = new Dimension();
		hud.getLayer().getDimension(d);
		hud.setColor(Color.black);
		hud.fillRect(0, 0, d.width, d.height);
	}
	
	/*============================================================
	Private Classes
	============================================================*/

	/** An implementation of a timer listener. **/
	private final class TimerListenerImpl implements TimerListener {

		@Override public void onAlarm(Timer timer, WorldArea world) {
			BlackOverlay overlay = BlackOverlay.this;
			world.destroyInstance(overlay);
		}
		
	}

}
